﻿<%@ WebHandler Language="C#" Class="SubjectHandler" %>

using System;
using System.Web;

using Manager;
using Util;
public class SubjectHandler : BaseAjaxHandler {

    /// <summary>
    /// 映射方法
    /// </summary>
    protected override void Mapping()
    {
        OprationMap["get"] = "GetSubject";         // 获得应用主题
        OprationMap["validate"] = "ValidateView";  // 验证查看权限
    }

    public void GetSubject()
    {
        int sid = int.Parse(Context.Request["sid"]);

        SubjectManager m = new SubjectManager();
        Subject s = m.GetSubject(sid);
        
        WriteTemplateResponse(true,JsonHelper.Serialize(s));
    }

    public void ValidateView()
    {
        int sid = int.Parse(Context.Request["sid"]);
        char viewLimit = char.Parse(Context.Request["viewLimit"]);
        string viewCode = Context.Request["viewCode"];
        
        bool result = false;
        
        if(viewLimit == Constants.VIEW_LIMIT_REQUIRES_CODE){
            SubjectManager m = new SubjectManager();
            if (m.ValidateViewLimit(sid, viewCode))
            {
                result = true;
            }
        }

        WriteTemplateResponse(result, JsonHelper.Serialize("验证结果"));
    }

}